/*
 * InDir1BlockTest.cpp
 *
 *  Created on: Apr 21, 2011
 *      Author: stefan
 */
#include <iostream>

#include "../core/InDir1Block.h"
#include "../testset/TestSet.hpp"

TEST_SET(InDir1BlockTest);

TEST(InDir1BlockConstructorTest)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	long address = block->getAddress(0);
	CHECK (address == -1l);
	delete block;
END_TEST

TEST(InDir1BlockAddAdressTestGood1)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,0);
	long address = block->getAddress(0);
	CHECK (address == 1l);
	address = block->getAddress(1);
	CHECK (address == -1l);
	delete block;
END_TEST

TEST(InDir1BlockAddAdressTestGood2)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,0);
	block->addAddress(3,1);
	long address = block->getAddress(0);
	CHECK (address == 1l);
	address = block->getAddress(1);
	CHECK (address == 3l);
	delete block;
END_TEST

TEST(InDir1BlockAddAdressTestBad1)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,-1);
	long address = block->getAddress(0);
	CHECK (address == -1l);
	address = block->getAddress(-1);
	CHECK (address == -2l);
	delete block;
END_TEST

TEST(InDir1BlockAddAdressTestBad2)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,130);
	long address = block->getAddress(0);
	CHECK (address == -1l);
	address = block->getAddress(130);
	CHECK (address == -2l);
	delete block;
END_TEST

TEST(InDir1BlockRemoveAdressTestGood1)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,0);
	long address = block->getAddress(0);
	CHECK (address == 1l);
	block->removeAddress(0);
	address = block->getAddress(0);
	CHECK (address == -1l);
	delete block;
END_TEST

TEST(InDir1BlockRemoveAdressTestGood2)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,0);
	block->addAddress(3,1);
	block->addAddress(5,2);
	long address = block->getAddress(1);
	CHECK (address == 3l);
	block->removeAddress(1);
	address = block->getAddress(1);
	CHECK (address == -1l);
	delete block;
END_TEST

TEST(InDir1BlockRemoveAdressTestBad)
	char* d = (char*) "hallo";
	byte* data = (byte*)d;
	InDir1Block* block = new InDir1Block(0, data);
	block->addAddress(1,0);
	long address = block->getAddress(0);
	CHECK (address == 1l);
	block->removeAddress(3);
	address = block->getAddress(0);
	CHECK (address == 1l);
	delete block;
END_TEST
